package main

import "fmt"

type PayInterface interface {
	AccountInterface
	Pay(price int) bool
}

type AccountInterface interface {
	GetBalance() int
}

type Credit struct {
	balance int
}

type Debit struct {
	balance int
}

// 实现PayInterface接口
func (credit *Credit) Pay(price int) bool {
	if credit.balance < price {
		fmt.Println("余额不足")
		return false
	} else {
		credit.balance -= price
		fmt.Printf("消费金额:%d\n", price)
		return true
	}
}

func (credit *Credit) GetBalance() int {
	return credit.balance
}

func purchase(payInterface PayInterface, price int) {
	payInterface.Pay(price)
	payInterface.GetBalance()
}

func main() {
	credit := Credit{balance: 1000}
	fmt.Println(credit.GetBalance())
	fmt.Println(credit.Pay(100))
	fmt.Println(credit.GetBalance())

	purchase(&credit, 500)
	fmt.Println(credit.GetBalance())
}
